<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of category
 * 
 * @author Joydeb Choudhury (mcajoydeb@gmail.com)
 */
class Password_change extends MX_Controller {

    //put your code here


    function password_change() {
        parent :: __construct();
		$this->load->model(array('admin_commoncall','admin_settings_model'));
        $this->load->model('settings_model');
               
        //$this->admin_commoncall->check_admin_login();
		$this->template
		->set_layout('default') // application/views/layouts/two_col.php
		->set_theme('admin'); // application/views/layouts/two_col.php
		$this->template->set_partial('nav_bar','layouts/nav_bar');
		$this->template->set_partial('side_menu','layouts/side_menu');
		$this->template->set_partial('footer', 'footer/footer');
    }

    function index()
    {        
		
		$this->template->build('settings/password_change');
    }

function pass_change() {
	
        if ($this->input->post('verify')) {
            $this->form_validation->set_rules('oldPass', 'Old Password', 'required|xss_clean');
            $this->form_validation->set_rules('newPass', 'New Password', 'required|xss_clean ');
            $this->form_validation->set_rules('repeatPass', 'Repeat Password', 'required|xss_clean|matches[newPass]');
			
            if ($this->form_validation->run()) {
                if ($this->session->userdata('sess_admin_password') == trim($this->input->post('oldPass'))) {
                   $data=array('password'=>$this->input->post('newPass'));
                   
                   //print_r($data);
                   //die();
                    $this->db->where('name',$this->session->userdata('sess_admin_name'));
                    $this->db->update('member',$data);
					$this->session->set_flashdata('message', 'Password Changed Sucessfully Login with new Password....!');
					redirect('secure/settings/password_change');
                    
                } else {
                    $this->session->set_flashdata('message', 'Old password is wrong!');
					redirect('secure/settings/password_change');				
                }
            } else {
                $this->session->set_flashdata('message', 'Field is empty or new password is mismatched with confirm password! ');
				redirect('secure/settings/password_change');
            }
        }
    }
        
}

?>
